// 抛射物 子弹、火球
class Projectile extends Moveable{
  constructor({name, type, x, y, width, height, game, hp, speed, angle}) {
    super({name, type, x, y, width, height, game, hp, speed})
    this.angle = angle
    this.rotateTick = 0;
    this.rotateDeg = 0;
    this.activeEngine = setInterval(() => {
      let now = Date.now()
      if(!this.rotateTick && now - this.rotateTick > 50){
        let deg = this.rotateDeg + 2;
        if(deg > 360) {
          deg = 0
        }
        this.rotateDeg = deg;
      }
      const rst = this.preMove(speed, true)
      this.move(rst.x, rst.y);
      if(rst.isOutSide) {
        this.emit('outSide', this)
      }
    }, 10)
  }
  release() {
    clearInterval(this.activeEngine);
    this.activeEngine = null;
    super.release();
  }
}